package com.i_art_engineer.meigong.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.i_art_engineer.meigong.R;
import com.squareup.picasso.Picasso;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 *
 */
public class PhrasesListAdapter extends BaseAdapter {

    private LayoutInflater mInflater;

    private Context mContext;

    private List<String> mData = new ArrayList<>();

    public PhrasesListAdapter(Context context) {
        mContext = context;
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    /**
     * 设置数据集
     *
     * @param data
     */
    public void setData(List<String> data) {
        if (data != null && data.size() > 0) {
            mData = data;
        } else {
            mData.clear();
        }
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public String getItem(int i) {
        return mData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = mInflater.inflate(R.layout.item_account_phrase, viewGroup, false);
            holder = new ViewHolder(view);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        if (holder != null) {
            holder.bindData(getItem(i));
        }

        return view;
    }

    public class ViewHolder {

        ImageView edit;
        TextView text;
        ImageView delete;

        ViewHolder(View view) {
            text = (TextView) view.findViewById(R.id.tv_tips);
            edit = (ImageView) view.findViewById(R.id.iv_phrase_edit);
            delete = (ImageView) view.findViewById(R.id.iv_phrase_delete);
            view.setTag(this);
        }

        void bindData(final String data) {
            text.setText(data);
        }

    }

}
